package com.glance.browser.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.glance.browser.domain.KnowledgeItem;
import com.glance.browser.repository.KnowledgeItemRepository;

@Repository
@Transactional(readOnly = true)
public class KnowledgeItemDAOImpl implements KnowledgeItemDAO{

	@Autowired
	private KnowledgeItemRepository repository;
	
	@Transactional
	public void deleteAllAfter(long id) {
		repository.deleteAllAfter(id);
	}
	
	public List<KnowledgeItem> findByTitle(String title) {
		return repository.findByTitle(title);
	}

	public List<KnowledgeItem> findByAuthor(String firstName, String lastName) {
		return repository.findByAuthor(firstName, lastName);
	}

	public KnowledgeItem findById(Long id) {
		return repository.findOne(id);
	}

	@Transactional
	public void save(KnowledgeItem ki) {
		repository.save(ki);
	}

	@Transactional
	public void delete(KnowledgeItem ki) {
		repository.delete(ki);
	}
	
}
